﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class DepartmentDAL
    {
        public DepartmentDAL(HoteContext hoteContext)
        {
            HoteContext = hoteContext;
        }

        public HoteContext HoteContext { get; }
        /// <summary>
        /// 科室添加
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int DepartAdd(DepartmentModel info)
        {
            try
            {
                var res = HoteContext.DepKeshi.Count(o => o.IsDelete == false && o.Department == info.Department);
                if (res > 0)
                {
                    return -1;//科室名称不能重复
                }
                 HoteContext.DepKeshi.Add(info);
                return HoteContext.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 显示查询 
        /// </summary>
        /// <param name="Departmen"></param>
        /// <returns></returns>
        public List<DepartmentModel> GetDepartmentList(string? Departmen="")
        {
            try
            {
                var list = HoteContext.DepKeshi.Where(o => o.IsDelete == false).ToList();
                if (!string.IsNullOrEmpty(Departmen))
                {
                    list=list.Where(o=>o.Department.Contains(Departmen)).ToList();
                }
                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
